--[[/**
-- * 
* 镜盾可以抵挡1次伤害，额外抵挡次数取决于每个英雄已损失生命值，每损失[1]%生命值可获得[0]次伤害抵挡效果
-- *
-- */]]

---@class BuffEffect412100 : BaseBuffEffect
BuffEffect412100 = ClientFight.CreateClass("BuffEffect412100", ClientFight.BaseBuffEffect)
local t = BuffEffect412100
t.BUFF_EFFECT_412100_TIMES = "BUFF_EFFECT_412100_TIMES";
---@param fight Fight
---@param buff FighterBuff
function t:add(fight, buff)
    local target = buff.target;
    local effectVal = buff.buffBean.f_BuffEffectValue;
    local maxHp = FighterAttributeManager.getFightAttr(target, FighterAttributeEnum.HP);
    local losePercent = 10000 - target.hp * 1 / maxHp * 10000;
    local multiple = (losePercent / effectVal[2]);
    local times = (effectVal[1] + multiple);
    buff.effectParams[t.BUFF_EFFECT_412100_TIMES] = times;

    SkillRoleMgr.savePathFile(string.format("[%s][EFFECT]Fighter %s  Buff%s 镜盾可抵挡%s次伤害",
            fight.frame, buff.target.fighterId, buff.modelId, times
    ));

    return super.add(fight, buff);
end

---@param fight Fight
---@param buff FighterBuff
function t:action(fight, buff, ...)
    local parameters = {...};
    if (table.getn(parameters) < 3) then
        return ClientFight.BaseBuffEffect.action(self, fight, buff, ...);
    end
    if (not parameters[3]) then
        return ClientFight.BaseBuffEffect.action(self, fight, buff, ...);

    end
    local fightResult = parameters[3];
    if (not AttackUtils.isDamage(fightResult.state)) then
        return ClientFight.BaseBuffEffect.action(self, fight, buff, ...);

    end
    local times = buff.effectParams[t.BUFF_EFFECT_412100_TIMES] or 0;
    if (times <= 0) then
        return IBuffEffect.REMOVE;
    end

    fightResult.damage = 0;
    fightResult.state = DamageResultTypeEnum.NONE;
    times = times - 1;

    SkillRoleMgr.savePathFile(string.format("[%s][EFFECT]Fighter %s  Buff%s 镜盾抵挡了一次伤害",
            fight.frame, buff.target.fighterId, buff.modelId
    ));

    if (times <= 0) then
        return IBuffEffect.REMOVE;
    end
    buff.effectParams[t.BUFF_EFFECT_412100_TIMES] = times;
    return ClientFight.BaseBuffEffect.action(self, fight, buff, ...);
end

t.New()